/*
 * Copyright (c) Huawei Technologies Co.,Ltd. 2023. All rights reserved.
 */
package common.testcase;

import org.opengauss.driver.DriverInfoManager;
import org.opengauss.driver.IDriverInfo;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Title: the BaseJdbcTestCase2 class.
 * <p>
 * Description:
 *
 * @author justbk
 * @version [Tools 0.0.1, 2023/7/21]
 * @since 2023/7/21
 */
public class BaseJdbcTestCase2 extends BaseJdbcTestCase {
    protected IDriverInfo driverInfo;
    protected Connection conn;
    public BaseJdbcTestCase2() {
        super();
        driverInfo = getDriverInfo();
    }
    @Override
    public Connection getConn() {
        if (conn == null) {
            conn = getNewConnection();
        }
        return conn;
    }
    
    public String getInfoKey() {
        return DriverInfoManager.instance.getActivity();
    }
    
    protected IDriverInfo getDriverInfo() {
        return DriverInfoManager.getInfo(getInfoKey());
    }
    @Override
    public Connection getNewConnection() {
        try {
            return DriverInfoManager.getConnection(driverInfo);
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
        }
        return null;
    }
    
    @Override
    public String getTableName() {
        return this.getClass().getName().replace(".", "_") + "_jdbc";
    }
    
    @Override
    public String getTableColumns4Create() {
        return null;
    }
}
